﻿using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Linq;
using System.Text;

namespace DataAccessService.IService
{
    public interface ISqliteService
    {
        SQLiteConnection GetConn();

        /// <summary>
        /// 根据条件查询
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="whereClause">查询条件(例如:name='张三')</param>
        /// <returns></returns>
        List<T> GetList<T>(string whereClause);

        /// <summary>
        /// 根据sql查询
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <returns></returns>
        List<T> QueryList<T>(string sql);

        /// <summary>
        /// 新增数据
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="item">实体</param>
        /// <returns></returns>
        bool AddItem<T>(T item, string idField);

        /// <summary>
        /// 新增数据
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="conn">数据库连接</param>
        /// <param name="tran">事务</param>
        /// <param name="idField">id字段</param>
        /// <param name="item">实体</param>
        /// <returns></returns>
        bool AddItem<T>(SQLiteConnection conn, SQLiteTransaction tran, T item, string idField);

        /// <summary>
        /// 编辑数据
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="idField">id字段</param>
        /// <param name="item">实体</param>
        /// <param name="id">数据id</param>
        /// <returns></returns>
        bool UpdateItem<T>(T item, string idField, string id);

        /// <summary>
        /// 编辑数据
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="idField">id字段</param>
        /// <param name="conn">数据库连接</param>
        /// <param name="tran">事务</param>
        /// <param name="item">实体</param>
        /// <param name="id">数据id</param>
        /// <returns></returns>
        bool UpdateItem<T>(SQLiteConnection conn, SQLiteTransaction tran, T item, string idField, string id);

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="tableName">表名称/实体名称</param>
        /// <param name="idField">id字段</param>
        /// <param name="id">数据id</param>
        /// <returns></returns>
        bool DeleteItem(string tableName, string idField, string id);

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="conn">数据库连接</param>
        /// <param name="tran">事务</param>
        /// <param name="tableName">表名称/实体名称</param>
        /// <param name="idField">id字段</param>
        /// <param name="id">数据id</param>
        /// <returns></returns>
        bool DeleteItem(SQLiteConnection conn, SQLiteTransaction tran, string tableName, string idField, string id);

        /// <summary>
        /// 执行任意sql
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="sql"></param>
        /// <returns></returns>
        bool ExcuteSql(SQLiteConnection conn, string sql);

        /// <summary>
        /// 执行任意sql(带事务)
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="tran"></param>
        /// <param name="sql"></param>
        /// <returns></returns>
        bool ExcuteSql(SQLiteConnection conn, SQLiteTransaction tran, string sql);
    }
}
